# -*- coding: utf-8 -*-

import scrapy
import re
import datetime
# from test1.items import cefpr


class cefprspider(scrapy.Spider):
    name = 'cefpr'
    start_urls = ['http://cefpr.cnca.cn/efpe/a/cer/tBzApplyCer/morelist']

    def parse(self, response):
        #print response.body
        pages = response.xpath("//body/div[@class='pagination']/ul/li[11]/a/text()").extract_first()
        # print pages
        for i in range (1,int(pages)+1):
            yield scrapy.FormRequest("http://cefpr.cnca.cn/efpe/a/cer/tBzApplyCer/morelist",
                                     formdata={
                                        'pageNo':str(i),
                                        'pageSize':'10'

                                     },
                                     callback=self.parse_goto)

    def parse_goto(self,response):
        #print response.body
        trs = response.xpath("//body/table[@id='contentTable']/tbody/tr")
        for tr in trs:
            name = tr.xpath("td[3]/text()").extract_first()
            print name